package com.smartparking.config;

import com.smartparking.entity.User;
import com.smartparking.repository.UserRepository;
import jakarta.annotation.PostConstruct;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.Set;

//@Component
//public class DataInitializer {
//    private final UserRepository userRepository;
//    private final ParkingSpotRepository spotRepository;
//    private final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
//
//    public DataInitializer(UserRepository userRepository, ParkingSpotRepository spotRepository) {
//        this.userRepository = userRepository;
//        this.spotRepository = spotRepository;
//    }
//
//    @PostConstruct
//    public void init() {
//        if (userRepository.count() == 0) {
//            User admin = User.builder()
//                    .username("admin")
//                    .password(encoder.encode("admin123"))
//                    .roles((Set<String>) Arrays.asList("ADMIN", "USER"))
//                    .build();
//            userRepository.save(admin);
//        }
//        if (spotRepository.count() == 0) {
//            IntStream.rangeClosed(1, 50).forEach(i -> {
//                ParkingSpot s = ParkingSpot.builder()
//                        .spotCode("P" + String.format("%03d", i))
//                        .status("available")
//                        .build();
//                spotRepository.save(s);
//            });
//        }
//    }
//}
